<?php
/**
*
* @package ppkBB3cker
* @version $Id: memberlist_add1.php 1.000 2008-11-14 17:30:00 PPK $
* @copyright (c) 2008 PPK
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

if(!function_exists('display_forums'))
{
	include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
    $assign_vars=array();
              $ii=0;
                        $sql='SELECT p.*, t.topic_title, t.topic_first_post_id FROM '. TRACKER_PEERS_TABLE .' p LEFT JOIN '.ATTACHMENTS_TABLE." a ON p.torrent=a.attach_id LEFT JOIN ".TOPICS_TABLE." t ON a.post_msg_id=t.topic_first_post_id WHERE p.userid='$user_id' AND !p.to_go";
                                           $result=$db->sql_query($sql);
                                                              while($userlist=$db->sql_fetchrow($result))
                                                                                 {
                                                                                                       $ii+=1;     
                                                                                                                          }
                                                                                                                                    $template->assign_vars(array(
                                                                                                                                                 'TRACKER_USER_SSEED'           => $ii,
                                                                                                                                                           ));
                                                                                                                                                                    
                                                                                                                                                                              $i5=0;
                                                                                                                                                                                        $db->sql_freeresult($result);
                                                                                                                                                                                                            $sql='SELECT p.*, t.topic_title, t.topic_first_post_id, tt.size FROM '. TRACKER_PEERS_TABLE .' p LEFT JOIN '.ATTACHMENTS_TABLE." a ON p.torrent=a.attach_id LEFT JOIN ".TOPICS_TABLE." t ON a.post_msg_id=t.topic_first_post_id LEFT JOIN ".TRACKER_TORRENTS_TABLE." tt ON p.torrent=tt.id WHERE p.userid='$user_id' AND p.to_go";
                                                                                                                                                                                                                               $result=$db->sql_query($sql);
                                                                                                                                                                                                                                                  while($userlist=$db->sql_fetchrow($result))
                                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                                           $i5+=1;
                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                                                  $template->assign_vars(array(
                                                                                                                                                                                                                                                                                                                                               'TRACKER_USER_LLEECH'           => $i5
                                                                                                                                                                                                                                                                                                                                                         ));
                                                                                                                                                                                                                                                                                                                                                                   $db->sql_freeresult($result);
                                                                                                                                                                                                                                                                                                                                                                   

$is_admod=$auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_') ? 1 : 0;

$dt=time();
if($user->data['is_registered'])
{
	$u_update=$tracker_cron=array();
	$ppkbb_cron_jobs=my_split_config($config['ppkbb_cron_jobs'], 3, 'my_int_val');
	$user_tracker_data=my_split_config($member['user_tracker_data'], 3, 'my_int_val');
	$u_update[0]=$u_update[1]=$u_update[2]=0;
	if($ppkbb_cron_jobs[0] && $dt-$user_tracker_data[0] > $ppkbb_cron_jobs[0]*60*60)
	{
		$u_update[0]=1;
	}
	if($ppkbb_cron_jobs[1] && $dt-$user_tracker_data[1] > $ppkbb_cron_jobs[1]*60*60)
	{
		$u_update[1]=1;
	}
	if(sizeof($u_update) && array_sum($u_update))
	{
		$u_update[3]=$member['user_id'];
		$u_update[4]=$member['user_tracker_data'];
		$sql="INSERT INTO ".TRACKER_CRON_TABLE."(type, data, forum_id, added) VALUES('u_update', '".$db->sql_escape(serialize($u_update))."', '0', '$dt')";
		$db->sql_query($sql);
		$cron_id=$db->sql_nextid();
		if($cron_id)
		{
			$tracker_cron[]=$cron_id;
		}
		if(sizeof($tracker_cron))
		{
			$cron_id=implode('&amp;id[]=', $tracker_cron);
			$template->assign_block_vars('tracker_cron', array(
				'CRON_TASK'=>'<img src="' . append_sid($phpbb_root_path . 'tracker/cron.' . $phpEx, 'id[]='.$cron_id) . '" alt="cron" width="1" height="1" />'
				)
			);
		}
	}
}

$template->assign_vars(array(
	'TRACKER_USER_TORRENTS'		=> '<a href="'.append_sid("{$phpbb_root_path}search.$phpEx", "search_id=egosearch&amp;torrent=my&amp;u=".$user_id).'">'.$member['user_torrents'].'</a>',
	'TRACKER_USER_COMMENTS'		=> '<a href="'.append_sid("{$phpbb_root_path}search.$phpEx", "search_id=egosearch&amp;torrent=mycomment&amp;u=".$user_id).'">'.$member['user_comments'].'</a>',
	'TRACKER_USER_UPLOAD'		=> get_formatted_filesize($member['user_uploaded']),
	'TRACKER_USER_DOWNLOAD'		=> get_formatted_filesize($member['user_downloaded']),
	'TRACKER_USER_REALDOWNLOAD'		=> get_formatted_filesize($member['user_shadow_downloaded']),
	'TRACKER_USER_BONUS'		=> $member['user_bonus'],
	'TRACKER_USER_YTHANKS'		=> $member['user_fromthanks_count'],
	'TRACKER_USER_TYTHANKS'		=> $member['user_tothanks_count'],
	'TRACKER_USER_YSEEDREQ'		=> $member['user_fromseedreq_count'],
	'TRACKER_USER_TYSEEDREQ'		=> $member['user_toseedreq_count'],
	'TRACKER_USER_RRATIO'		=> get_ratio($member['user_uploaded'], $member['user_shadow_downloaded']),
	'TRACKER_USER_RATIO'		=> get_ratio($member['user_uploaded'], $member['user_downloaded'], $config['ppkbb_tcratio_start'], $member['user_bonus']),
	//'TRACKER_USER_PASSKEY'		=> $member['user_id']==$user->data['user_id'] || $is_admod ? $member['user_passkey'] : '',
));

$torrent_opt=request_var('opt', '');
$torrent_info_curr='';

$torrent_info_curr_explain=$assign_vars=$torrent_info=$sort_opt=$postrow_header=$postrow_headers=array();
$i3=0;

$memberlist_url=append_sid("memberlist.$phpEx", "mode=viewprofile&amp;u=".$user_id);
$torrent_info['torrent']="<a href='{$memberlist_url}&amp;opt=torrent&amp;optp=topic_title#opt'>{$user->lang['USER_TORRENT']}</a>";
$torrent_info['finished']="<a href='{$memberlist_url}&amp;opt=finished&amp;optp=topic_title#opt'>{$user->lang['USER_TORRENT_FINISH']}</a>";
$torrent_info['seed']="<a href='{$memberlist_url}&amp;opt=seed&amp;optp=topic_title#opt'>{$user->lang['USER_TORRENT_SEED']}</a>";
$torrent_info['leech']="<a href='{$memberlist_url}&amp;opt=leech&amp;optp=topic_title#opt'>{$user->lang['USER_TORRENT_LEECH']}</a>";
$torrent_info['tothanks']="<a href='{$memberlist_url}&amp;opt=tothanks&amp;optp=username#opt'>{$user->lang['USER_TORRENT_TOTHANKS']}</a>";
$torrent_info['fromthanks']="<a href='{$memberlist_url}&amp;opt=fromthanks&amp;optp=username#opt'>{$user->lang['USER_TORRENT_FROMTHANKS']}</a>";
$torrent_info['history']="<a href='{$memberlist_url}&amp;opt=history&amp;optp=topic_title#opt'>{$user->lang['USER_TORRENT_HISTORY']}</a>";
$torrent_info['leave']="<a href='{$memberlist_url}&amp;opt=leave&amp;optp=topic_title#opt'>{$user->lang['USER_TORRENT_LEAVE']}</a>";
$config['ppkbb_srenable'] ? $torrent_info['fromseedreq']="<a href='{$memberlist_url}&amp;opt=fromseedreq&amp;optp=username#opt'>{$user->lang['USER_TORRENT_FROMSEEDREQ']}</a>" : '';

$opt_sort=request_var('opts', '');
$opt_param=request_var('optp', '');
$opt_sort=='ASC' ? '' : $opt_sort='DESC';
!$config['ppkbb_srenable'] && $torrent_opt=='seedreq' ? $torrent_opt='' : '';
$mua_add1inc=$phpbb_root_path.'tracker/include/';
$mua='memberlist';
switch($torrent_opt)
{
	case 'leave':
		include($mua_add1inc.'mua_add1_leave.'.$phpEx);
		break;

	case 'history':
		include($mua_add1inc.'mua_add1_history.'.$phpEx);
		break;

	case 'finished':
		include($mua_add1inc.'mua_add1_finished.'.$phpEx);
		break;

	case 'seed':
		include($mua_add1inc.'mua_add1_seed.'.$phpEx);
		break;

	case 'leech':
		include($mua_add1inc.'mua_add1_leech.'.$phpEx);
		break;

	case 'tothanks':
		include($mua_add1inc.'mua_add1_tothanks.'.$phpEx);
		break;

	case 'fromthanks':
		include($mua_add1inc.'mua_add1_fromthanks.'.$phpEx);
		break;

	case 'torrent':
		include($mua_add1inc.'mua_add1_torrent.'.$phpEx);
		break;

	case 'fromseedreq':
		include($mua_add1inc.'mua_add1_fromseedreq.'.$phpEx);
		break;

	default:
		$torrent_opt='';
		break;
}
$db->sql_freeresult($result);

$template->assign_vars(array(
	'S_HAS_TORRENT_EXPLAIN'	=> $torrent_info_curr ? true : false,
	'S_HAS_TORRENT_EXPLAIN_TORRENT'	=> @$torrent_info_curr_explain['torrent'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_FINISHED'	=> @$torrent_info_curr_explain['finished'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_FROMTHANKS'=> @$torrent_info_curr_explain['fromthanks'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_TOTHANKS'	=> @$torrent_info_curr_explain['tothanks'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_HISTORY'	=> @$torrent_info_curr_explain['history'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_LEAVE'	=> @$torrent_info_curr_explain['leave'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_SEED'	=> @$torrent_info_curr_explain['seed'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_LEECH'	=> @$torrent_info_curr_explain['leech'] ? true : false,
	'S_HAS_TORRENT_EXPLAIN_FROMSEEDREQ'=> @$torrent_info_curr_explain['fromseedreq'] ? true : false,
	'TORRENT_INFO_OPT'=> $torrent_info ? implode(' : ', $torrent_info) : false,
));

if($assign_vars)
{
	foreach($assign_vars as $k2 => $v2)
	{
		$template->assign_block_vars($torrent_info_curr.'_option', $v2);
	}
}
if($postrow_headers)
{
	foreach($postrow_headers as $k2 => $v2)
	{
		$template->assign_block_vars('headers', array('VALUE' => $v2));
	}
}

if($postrow_header)
{
	$template->assign_var('S_TORRENT_FOOTER', implode(' : ', $postrow_header));
}
?>
